package com.ruoyi.service.impl;

import java.util.List;

import com.ruoyi.domain.BasisReceiver;
import com.ruoyi.dto.BasisPositionReceiver;
import com.ruoyi.mapper.BasisReceiverMapper;
import com.ruoyi.service.IBasisReceiverService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 接收设备名称与接收设备类型关联Service业务层处理
 * 
 * @author wangzebing
 * @date 2025-07-05
 */
@Service
public class BasisReceiverServiceImpl implements IBasisReceiverService
{
    @Autowired
    private BasisReceiverMapper basisReceiverMapper;

    /**
     * 查询接收设备名称与接收设备类型关联
     * 
     * @param id 接收设备名称与接收设备类型关联主键
     * @return 接收设备名称与接收设备类型关联
     */
    @Override
    public BasisReceiver selectBasisReceiverById(Long id)
    {
        return basisReceiverMapper.selectBasisReceiverById(id);
    }

    /**
     * 查询接收设备名称与接收设备类型关联列表
     * 
     * @param basisReceiver 接收设备名称与接收设备类型关联
     * @return 接收设备名称与接收设备类型关联
     */
    @Override
    public List<BasisReceiver> selectBasisReceiverList(BasisReceiver basisReceiver)
    {
        return basisReceiverMapper.selectBasisReceiverList(basisReceiver);
    }

    /**
     * 新增接收设备名称与接收设备类型关联
     * 
     * @param basisReceiver 接收设备名称与接收设备类型关联
     * @return 结果
     */
    @Override
    public int insertBasisReceiver(BasisReceiver basisReceiver)
    {
        BasisPositionReceiver basisPositionReceiver = new BasisPositionReceiver();
        int i = basisReceiverMapper.insertBasisReceiver(basisReceiver);
        if (i > 0 ){
            basisPositionReceiver.setReceiverId(Math.toIntExact(basisReceiver.getId()));
            basisPositionReceiver.setLoadingId(basisReceiver.getLoadingId());
            basisPositionReceiver.setPositionId(basisReceiver.getPositionId());
            basisReceiverMapper.addBasisPositionReceiver(basisPositionReceiver);
        }

        return i;
    }

    /**
     * 修改接收设备名称与接收设备类型关联
     * 
     * @param basisReceiver 接收设备名称与接收设备类型关联
     * @return 结果
     */
    @Override
    public int updateBasisReceiver(BasisReceiver basisReceiver)
    {
        return basisReceiverMapper.updateBasisReceiver(basisReceiver);
    }

    /**
     * 批量删除接收设备名称与接收设备类型关联
     * 
     * @param ids 需要删除的接收设备名称与接收设备类型关联主键
     * @return 结果
     */
    @Override
    public int deleteBasisReceiverByIds(Long[] ids)
    {
        return basisReceiverMapper.deleteBasisReceiverByIds(ids);
    }

    /**
     * 删除接收设备名称与接收设备类型关联信息
     * 
     * @param id 接收设备名称与接收设备类型关联主键
     * @return 结果
     */
    @Override
    public int deleteBasisReceiverById(Long id)
    {
        return basisReceiverMapper.deleteBasisReceiverById(id);
    }

    @Override
    public int deleteBasisReceiverById2(BasisPositionReceiver basisPositionReceiver) {
        int i = basisReceiverMapper.deleteBasisReceiverById(basisPositionReceiver.getReceiverId().longValue());
        if (i > 0){
            boolean b = basisReceiverMapper.delBasisPositionReceiver(basisPositionReceiver);
            if (!b) return 0;
        }

        return i;
    }

    @Override
    public List<BasisReceiver> findByLoadingIdAndPositionId(String loadingId, String positionId) {
        return basisReceiverMapper.findByLoadingIdAndPositionId(loadingId, positionId);
    }
}
